<template>
  <el-table :data="tableData">
    <el-table-column prop="teachingProcess" label="教学环节" width="200" />
    <el-table-column prop="contentCourses" label="教学内容">
      <template #default="scope">
        <div class="whiteSpace">{{ scope.row.contentCourses }}</div>
      </template>
    </el-table-column>
    <el-table-column
      prop="teachingMethod"
      label="教学方法"
      width="320"
      align="center"
    >
      <template #default="scope">
        <div class="whiteSpace">{{ scope.row.teachingMethod }}</div>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup lang="ts">
import useCounterStore from "@/store/counter";
const counter = useCounterStore();
let props = defineProps(["info", "archiveBinding", "type"]);
const { proxy } = getCurrentInstance();

let tableData = ref([]);
let templateUrl;

async function getInfo() {
  if (props.archiveBinding.length) {
    tableData.value = await proxy.$apis.scheduleRelevant({
      type: "archives-appendix-list",
      data: { archivesId: props.archiveBinding[0]._id },
    });
  }
  console.log("教学附表", tableData.value);
}

async function exportWord() {
  let url = await proxy.$apis.classDocExport({
    templateURL: templateUrl,
    data: {
      list: await counter.lessonPlanAppendixExportParams(props.info._id),
    },
    fileName: "教案附表.docx",
  });
  window.location.href = url;
}

async function getTemplateUrl() {
  templateUrl = await proxy.$apis.fileTemplate({
    data: { type: props.type },
    type: "downLoad",
  });
}

function downLoadTemplate() {
  window.location.href = templateUrl;
}

watch(
  () => [props.info, props.archiveBinding],
  (newValue, oldValue) => {
    if (newValue) {
      getTemplateUrl();
      getInfo();
    }
  },
  { deep: true, immediate: true }
);

defineExpose({ exportWord, downLoadTemplate, getTemplateUrl });
</script>

<style lang="scss" scoped>
.container {
}
</style>
